﻿using HoverTree.DBTools.OleDatabase;
using HoverTree.Framework;
using HoverTree.IDAL;
using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;

namespace HoverTree.OleDbDAL
{
    /**/
    /// <summary>
    /// The OleDbHelper class is intended to encapsulate high performance, 
    /// scalable best practices for common uses of OleDb.
    /// </summary>
    public  class UserMessage : IUserMessage
    {
        public string Add(string hvtTitle, string hvtContent, string hvtUser)
        {
            string m_sql = "insert into hovertree_usermessage (hvtTitle,hvtContent,hvtUser)values("
              + SQLTools.GetQuotes(hvtTitle) + ","
              + SQLTools.GetQuotes(hvtContent) + ","
              + SQLTools.GetQuotes(hvtUser) + ")";
            int m_i = OleDbHelper.ExecuteNonQuery(m_sql);
            if (m_i == 1)
                return string.Empty;
            else
                return "添加失败";
        }

        public DataTable GetLast500()
        {
            string m_sql = "select top 500 * from hovertree_usermessage order by hvtid desc";
            return OleDbHelper.ExecuteDataSet(m_sql).Tables[0];
        }

        public DataRow Get(int id)
        {
            string m_sql = "select  * from hovertree_usermessage where hvtid=" + id.ToString();
            return OleDbHelper.ExecuteDataSet(m_sql).Tables[0].Rows[0];
        }

        public string Handle(int id, bool isshow, string reply)
        {
            string m_sql = "update hovertree_usermessage set hvtreply="
              + SQLTools.GetQuotes(reply) + ","
              + "hvtisshow=" + Convert.ToInt32(isshow).ToString() + " where hvtid=" + id.ToString();

            return OleDbHelper.ExecuteNonQuery(m_sql) == 1 ? "" : "修改失败";
        }

        public DataTable GetLast100Public()
        {
            string m_sql = "select top 100 * from hovertree_usermessage where hvtisshow=true order by hvtid desc";
            return OleDbHelper.ExecuteDataSet(m_sql).Tables[0];
        }


        public DataTable HvtPageQuery(int sortType, int pageSize, int pageIndex, out int totalCount, out int totalPageCount)
        {
            throw new NotImplementedException();
        }
    }
}